﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using KingRoad.EPM.SafetyManagementBLL.Domain;
using KingRoad.EPM.SafetyManagementEntity.Model;
using Unis.Framework.Core.Utility;
using KingRoad.EPM.SafetyManagementDAL.ScmSafetyknowledgeService;


namespace KingRoad.EPM.SafetyManagementBLL.UIRules
{
    /// <summary> 
    /// 客户端业务处理类。 
    /// 文件生成时间 2017/1/18 15:06:07
    /// </summary> 
    public class ScmSafetyknowledgeUIRule
    {
        private readonly IScmSafetyknowledgeService _scmSafetyknowledgeService;


        public ScmSafetyknowledgeUIRule() { }

        /// <summary> 
        /// construct function... 
        /// </summary> 
        public ScmSafetyknowledgeUIRule(IScmSafetyknowledgeService scmSafetyknowledgeService)
        {
            _scmSafetyknowledgeService = scmSafetyknowledgeService;
        }

        /// <summary>
        /// 获取所有的安全知识信息
        /// </summary>
        /// <param name="numCurrentPage">当前页</param>
        /// <param name="numPerPage">每页数据大小</param>
        /// <param name="orderByField">排序字段名称</param>
        /// <param name="totalRecord">总数据量</param>
        /// <returns></returns>
        public List<ScmSafetyknowledgeInfo> GetAllSafetyknowledge(int numCurrentPage, int numPerPage, string orderByField, out int totalRecord)
        {
            var list = _scmSafetyknowledgeService.GetEntityListByContion(numCurrentPage, numPerPage, orderByField, out totalRecord);
            return list;
        }

        /// <summary>
        /// 根据条件查询安全知识信息
        /// </summary>
        /// <param name="numCurrentPage">当前页</param>
        /// <param name="numPerPage">每页数据大小</param>
        /// <param name="orderByField">排序字段名称</param>
        /// <param name="totalRecord">总数据量</param>
        /// <param name="sqlCondition">sql查询条件</param>
        /// <returns></returns>
        public List<ScmSafetyknowledgeInfo> GetSafetyknowledgeForSearch(int numCurrentPage, int numPerPage,
                                                                        string orderByField, out int totalRecord, string sqlCondition)
        {
            var list = _scmSafetyknowledgeService.GetEntityListByContionRe(numCurrentPage, numPerPage, orderByField, out totalRecord, sqlCondition);
            return list;
        }


        public ScmSafetyknowledgeInfo GetSafetyknowledgeById(string slId)
        {
            var sqlStr = String.Format(" Sk_ID='{0}' ", slId);
            var single = _scmSafetyknowledgeService.GetEntityList(sqlStr).FirstOrDefault();
            return single;
        }

        public bool InsertEntity(ScmSafetyknowledgeInfo entity)
        {
            var ret = _scmSafetyknowledgeService.InsertEntity(entity);
            return ret > 0;
        }

        public bool UpdateEntity(ScmSafetyknowledgeInfo entity)
        {
            var ret = _scmSafetyknowledgeService.UpdateEntity(entity);
            return ret > 0;
        }

        public bool DeleteEntity(string slId)
        {
            var ret = _scmSafetyknowledgeService.DeleteEntityByStringID(slId);
            return ret > 0;
        }

        /// <summary>
        /// 删除安全知识(批量删除)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleteSafeTrainningMulti(string id)
        {
            return _scmSafetyknowledgeService.DeleteEntityByMultiStringID(id);
        }

        /// <summary>
        /// 判断是否已经存在辅助ID（要求辅助ID必须唯一）
        /// </summary>
        /// <param name="assistId"></param>
        /// <returns></returns>
        public bool IsExitAssistId(int assistId)
        {
            var strSql = String.Format(" Assist_ID={0} ", assistId);
            var list = _scmSafetyknowledgeService.GetEntityList(strSql);
            return list.Any();
        }
    }
}
